package com.zzyl.controller;

import com.zzyl.Vo.UserpageVo;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserAddDto;
import com.zzyl.dto.UserlistDto;
import com.zzyl.dto.UserpageDto;
import com.zzyl.entity.User;
import com.zzyl.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<PageResponse<UserpageVo>> page(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize, @RequestBody UserpageDto dto) {
        PageResponse<UserpageVo> page = userService.page(pageNum, pageSize, dto);
        return ResponseResult.success(page);
    }

    @PutMapping
    public ResponseResult Add(@RequestBody UserAddDto dto) {
        userService.Add(dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "5.7 删除用户")
    @DeleteMapping("/remove/{userIds}")
    public ResponseResult shanchu(@PathVariable("userIds") Long id) {
        userService.shanchu(id);
        return ResponseResult.success();
    }

    @ApiOperation(value = "5.5 用户列表")
    @PostMapping("/list")
    public ResponseResult liebiao(@RequestBody UserlistDto dto) {
        List<User> users = userService.liebiao(dto);
        return ResponseResult.success(users);

    }

    @ApiOperation(value = "5.4 启用或禁用用户")
    @PutMapping("/is-enable/{id}/{status}")
    public ResponseResult qiyongjinyong(@PathVariable("id") Long id, @PathVariable("status") Integer status) {

        userService.qiyongjinyong(id, status);
        return ResponseResult.success();
    }

    @ApiOperation(value = "5.2 用户修改")
    @PatchMapping
    public ResponseResult xiugai(@RequestBody UserAddDto dto) {

        userService.xiugai(dto);
        return ResponseResult.success();

    }


    @ApiOperation(value = "5.8 密码重置")
    @PostMapping("/reset-passwords/{userId}")
    public ResponseResult mima(@PathVariable("userId") Long userId) {

        userService.mima(userId);
        return ResponseResult.success();

    }
}